<?php

namespace App\Admin\Controllers;

use App\Models\Scene;
use App\Models\SceneIncome;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class SceneIncomeController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('产业收入');
            $content->body($this->grid());
        });
    }
    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(SceneIncome::class, function (Grid $grid) {
            $grid->actions(function ($actions) {
                $actions->disableView();
            });
            $grid->filter(function($filter){
                $filter->disableIdFilter();
                $filter->between('date', '日期')->date();
            });
            $grid->disableExport();
            $grid->id('ID')->sortable();
            $grid->scene_id('景区')->display(function ($val){
                return $val!=null?Scene::where('is_docking',1)->find($val)->title:'';
            });
            $grid->day_income('日营业额');
            $grid->tax_revenue('总税收');
            $grid->ticket_revenue('门票收入');
            $grid->ticket_num('门票销售量');
            $grid->sales_channels('门票销售渠道');
            $grid->vav_revenue('车船营业额');
            $grid->other_revenue('其他收费项目营业额');
            $grid->date('日期');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(SceneIncome::class, function (Form $form) {
            $form->number('day_income', '日营业额');
            $form->number('tax_revenue', '总税收');
            $form->number('ticket_revenue', '门票收入');
            $form->number('ticket_num', '门票销售量');
            $form->number('vav_revenue', '车船营业额');
            $form->number('other_revenue', '其他收费项目营业额');
            $form->tags('sales_channels', '门票销售渠道');
            $form->date('date', '日期');

        });
    }
}
